/**
 * @author xinjie.txt
 * @time: 2020年6月30日 下午5:43:00
 */
package com.jiepu.daily.corejava.day0701;

/**
 * @Description:
 * @author xinjie.txt
 */
public class RandomDemo {

	public static void main(String[] args) {

		// double random = 0;
		// double random = Math.random()*10;
		// (0,10}
		for (int i = 0; i < 100; i++) {
			System.out.print(Math.random() * 10 + " ");
		}
		System.out.println();
		// 0-9
		System.out.println("0-9");
		for (int i = 0; i < 100; i++) {
			System.out.print((int) (Math.random() * 10) + " ");
		}
		System.out.println();
		// 1-10 0-10+1
		System.out.println("-----------------------------------");
		System.out.println("1-10");
		for (int i = 0; i < 100; i++) {
			System.out.print((int) ((Math.random() * 10) + 1) + " ");
		}
		System.out.println();

		// 13-28
		System.out.println("--------------------------");
		System.out.println("13-28");
		for (int i = 0; i < 100; i++) {
			System.out.print((int) (Math.random() * 16 + 13) + " ");
		}
		System.out.println();
		// 13-28
		// check();
		generateRandom(1, 100);
	}

	/**
	 * 
	 * @Description: 13-28 test 100w
	 */
	public static void check() {
		// 表示算法是否正确
		boolean flag = true;
		for (int i = 0; i < 10000000; i++) {
			int random = ((int) (Math.random() * 16 + 13));
			if (random < 13 || random > 28) {
				flag = false;

				break;
			}
		}

		System.out.println(flag ? "100w测试成功" : "100w侧试失败");
	}

	/**
	 * @note: 跨域： n-m+1 偏移量：m
	 * @Description: [m,n]的随机数
	 * @param m
	 * @param n
	 */
	public static void generateRandom(int m, int n) {
		// m n 大小
		if (m > n) {
			int temp;
			temp = m;
			m = n;
			n = temp;
		}
		int max = Math.max(m, n);
		int min = Math.min(m, n);
		int a=Math.abs(n);
		/**
		 * 不引人变量直接交换 m，n if(m>n) m=m+n; n=m-n; =m m=m-n; =n
		 */

		System.out.println((int) (Math.random() * (n - m + 1) + m));

	}

}
